﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PowerBooking.RSE.Domain.Models;
using PowerBooking.RSE.Utility.Helpers;
using PowerBooking.RSE.IRepository;
using PowerBooking.RSE.Contract.Enums;

namespace PowerBooking.RSE.Domain.Factories
{
    public class SpiderMonitorStaticFactory
    {
        public static Dictionary<long, SpiderMonitor> CreateSpiderMonitorDictionary()
        {
            var spiderMonitorDictionary = CacheHelper.Get<Dictionary<long, SpiderMonitor>>("SpiderMonitorDictionary");
            if (spiderMonitorDictionary == null)
            {
                spiderMonitorDictionary = new Dictionary<long, SpiderMonitor>();
                CacheHelper.Set("SpiderMonitorDictionary", spiderMonitorDictionary, DateTime.Now.AddYears(1));
            }
            return spiderMonitorDictionary;
        }

        public static SpiderMonitor GetSpiderMonitor(long spiderID)
        {
            var spiderMonitorDictionary = CacheHelper.Get<Dictionary<long, SpiderMonitor>>("SpiderMonitorDictionary");
            var spiderMonitor = default(SpiderMonitor);
            if (spiderMonitorDictionary.Keys.Contains(spiderID))
            {
                spiderMonitor = spiderMonitorDictionary[spiderID];
            }
            else
            {
                spiderMonitor = new SpiderMonitor().InitDomain(spiderID, 0, 0, 0,SpiderStatusEnum.Stop);
                spiderMonitorDictionary.Add(spiderID,spiderMonitor);
                CacheHelper.Set("SpiderMonitorDictionary", spiderMonitorDictionary, DateTime.Now.AddYears(1));
            }
            return spiderMonitor;
        }
    }
}
